/**
* 参数是否为空
* */
export function isEmpty (val) {
  return typeof val === "undefined" || val === null || val === "";
}
/**
 * 数字格式化为千分位
 * 支持负数，默认保持2位小数
 */
export function number_format(num, decimals) {
  let ret = ''
  let flag = ''
  let numString = num.toString()
  let numSplit = numString.split('.')
  if (typeof decimals === 'undefined' || decimals === '' || decimals === null) {
    decimals = 2
  }
  if (numSplit.length === 2 && decimals > 0) {
    ret = '.' + numSplit[1].substr(0, decimals)
  }
  numString = numSplit[0]
  if (numString.substr(0, 1) === '-') {
    numString = numString.substr(1)
    flag = '-'
  }
  while (numString.length > 3) {
    ret = ',' + numString.substr(numString.length - 3) + ret
    numString = numString.substr(0, numString.length - 3)
  }
  ret = flag + numString + ret
  return ret
}

/**
 * 文件大小格式转换
 * */
export function sizeFormat(size) {
  if (size < 1024) {
    size = size + 'B'
  } else if (size < 1024 * 1204) {
    size = parseFloat((size / 1024).toFixed(2)) + 'KB';
  } else {
    size = parseFloat((size / (1024 * 1024)).toFixed(2)) + 'M';
  }
  return size;
}
